package org.kzwl.book.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.kzwl.book.controller.annotation.PassToken;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.IsUserLiveBO;
import org.kzwl.comm.pojo.bo.IsUserLiveUpadteBO;
import org.kzwl.comm.pojo.bo.UserLoginBO;
import org.kzwl.comm.pojo.dto.UserLoginDTO;
import org.kzwl.comm.pojo.dto.user.UserTokenDTO;
import org.kzwl.entity.app.User;
import org.kzwl.service.app.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张国伟/郭家恒
 * @since 2020-09-10
 */
@RestController
@RequestMapping("/user")
@Api("用户业务")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户登录", notes = "cuUserLoginType(0-密码登录 1-手机号登录 2-一键登录)--必填 cuVerificationCode(验证码)--选填 cuUserPhone(手机号)--必填 cuUserPassword(密码)-选填")
    @PostMapping("/userLogin")
    @PassToken
    public ResponseData<UserLoginDTO> userLogin(@RequestBody UserLoginBO bo) {
        UserLoginDTO dto = userService.userLogin(bo);
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "手机号注册", notes = "cuUserPhone(手机号)--必填 cuUserPassword(密码)--必填 cuVerificationCode(验证码)--必填")
    @PostMapping("/register")
    @PassToken
    public ResponseData<Void> register(@RequestBody UserLoginBO bo) {
        userService.register(bo);
        return new ResponseData<>();
    }

    @ApiOperation(value = "发送短信", notes = "cuUserPhone(手机号)--必填")
    @PostMapping("/sendSms")
    @PassToken
    public ResponseData<Void> sendSms(@RequestBody UserLoginBO bo) {
        userService.sendSms(bo);
        return new ResponseData<>();
    }

    @ApiOperation(value = "根据token获取用户信息", notes = "jwt--必填")
    @PostMapping("/getUserByToken")
    public ResponseData<UserTokenDTO> getUserByToken(@RequestBody UserLoginDTO bo) {
        UserTokenDTO tokenDTO = userService.getUserByToken(bo);
        return new ResponseData<>(tokenDTO);
    }

    /**
     *
     * @param isUserLiveBO
     * @return
     */
    @PostMapping("/IsLiveQuery")
    public ResponseData<IPage<User>> IsLiveQuery(@RequestBody IsUserLiveBO isUserLiveBO)
    {
        return userService.IsLiveQuery(isUserLiveBO);
    }

    /**
     * 修改权限
     * @param isUserLiveUpadteBO
     * @return
     */
    @PostMapping("/updateIsLive")
    public ResponseData<Void> updateIsLive(@RequestBody IsUserLiveUpadteBO isUserLiveUpadteBO)
    {
        return userService.updateIsLive(isUserLiveUpadteBO);
    }



}
